script_enemy_main{

let starttime=90;

let speakingside=0;
let movecharacter=0;
let characterscroll=0;
let oldside=0;

let i=0;
let j=0;
let letter=0;
let letters=[];
let letterscale=[];
let letterfade=[];
let letterred=[];
let lettergreen=[];
let letterblue=[];

let line="";
let writingtime=0;
let nextline=0;
let newword=0;
let wordsize=0;
let lineypos=0;

let wait=0;
let busywriting=0;
let shortbreak=0;
let skipped=0;
let currentline=1;
let linenumber=1;
let textcolor=[0,0,0];
let newcolor=[textcolor[0],textcolor[1],textcolor[2],0,0,0];
let nameappear=0;

let lastline=22;
let waittime=180;
let enableZ=true;
let enableskip=true;

let GRtextbar=("\script\Images\OtherEffects\Textbar.png");
let GRtext=("\script\Images\OtherEffects\TextDialogue.png");
let GRnames=("\script\Images\OtherEffects\Names.png");

let SEtext=("\script\SoundEffects\text1.wav");

#include_function "script/Functions/PortraitsVariables.txt";

let OBJtextbar=0; let OBJtext=0; let OBJleft=0; let OBJright=0;
let textbarscale=0;

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let frame=0; let time=0;

@Initialize{
	SetLife(1000);
	SetX(cx);
	SetY(-1000);
	
	LoadPortrait("Masahiro",1);
	LoadPortrait("Kurumi",6);
	LoadPortrait("Hotaru",6);
	LoadPortrait("Tomoko",6);

	#include_function "script/Functions/PortraitsLoad.txt";
	
	SetCommonData("InEvent",1);
	SetCommonData("BackgroundStop",1);
	
	SetCommonData("Boss1Move",2);
	SetCommonData("Boss2Move",2);
}
	
@MainLoop{

CollectItems;

if(time==starttime){
	OBJtextbar=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJtextbar,6); Obj_SetPosition(OBJtextbar,cx,maxy-70); ObjEffect_SetTexture(OBJtextbar,GRtextbar);
	ObjEffect_SetRenderState(OBJtextbar,ALPHA); ObjEffect_SetScale(OBJtextbar,1,1);
	ObjEffect_SetScale(OBJtextbar,1,0);
	ObjEffect_SetPrimitiveType(OBJtextbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJtextbar,4);
	ObjEffect_SetVertexXY(OBJtextbar,0,-190,-50); ObjEffect_SetVertexUV(OBJtextbar,0,0,0);
	ObjEffect_SetVertexXY(OBJtextbar,1,190,-50); ObjEffect_SetVertexUV(OBJtextbar,1,380,0);
	ObjEffect_SetVertexXY(OBJtextbar,2,-190,50); ObjEffect_SetVertexUV(OBJtextbar,2,0,100);
	ObjEffect_SetVertexXY(OBJtextbar,3,190,50); ObjEffect_SetVertexUV(OBJtextbar,3,380,100);
	ObjEffect_SetVertexColor(OBJtextbar,0,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,1,200,255,255,255);
	ObjEffect_SetVertexColor(OBJtextbar,2,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,3,200,255,255,255);

	OBJleft=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJleft,5); Obj_SetPosition(OBJleft,cx-100,cy+60); ObjEffect_SetTexture(OBJleft,CHEmpty);
	ObjEffect_SetPrimitiveType(OBJleft,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJleft,4); ObjEffect_SetAngle(OBJleft,0,180,0);
	ObjEffect_SetVertexXY(OBJleft,0,-175,-175); ObjEffect_SetVertexUV(OBJleft,0,0,0);
	ObjEffect_SetVertexXY(OBJleft,1,175,-175); ObjEffect_SetVertexUV(OBJleft,1,350,0);
	ObjEffect_SetVertexXY(OBJleft,2,-175,175); ObjEffect_SetVertexUV(OBJleft,2,0,350);
	ObjEffect_SetVertexXY(OBJleft,3,175,175); ObjEffect_SetVertexUV(OBJleft,3,350,350);
	ObjEffect_SetVertexColor(OBJleft,0,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJleft,2,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,3,255,255,255,255);

	OBJright=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJright,5); Obj_SetPosition(OBJright,cx+100,cy+60); ObjEffect_SetTexture(OBJright,CHEmpty);
	ObjEffect_SetPrimitiveType(OBJright,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJright,4); ObjEffect_SetAngle(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,0,-175,-175); ObjEffect_SetVertexUV(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,1,175,-175); ObjEffect_SetVertexUV(OBJright,1,350,0);
	ObjEffect_SetVertexXY(OBJright,2,-175,175); ObjEffect_SetVertexUV(OBJright,2,0,350);
	ObjEffect_SetVertexXY(OBJright,3,175,175); ObjEffect_SetVertexUV(OBJright,3,350,350);
	ObjEffect_SetVertexColor(OBJright,0,255,255,255,255); ObjEffect_SetVertexColor(OBJright,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJright,2,255,255,255,255); ObjEffect_SetVertexColor(OBJright,3,255,255,255,255);
}
if(time>=starttime){

if(textbarscale<1 && linenumber<lastline){ textbarscale+=0.1; }
if(textbarscale>0 && linenumber==lastline){ textbarscale-=0.1; }
if(textbarscale<0){ Obj_Delete(OBJtextbar); }
ObjEffect_SetScale(OBJtextbar,1,textbarscale);

if(nextline==1){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline++; linenumber++; }
if(nextline==2){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline=lastline; linenumber=lastline; }


WriteLine(1,"Kurumi","Whoo!% This is awesome!+Everyone, look at me!+I`m the queen of Tanabata!",CHKurumiYukata01);
WriteLine(2,"Hotaru","Onee-san!+Get down from there!",CHHotaruYukata01);
WriteLine(3,"Masahiro","I see you two are having fun as well.",CHMasahiroNormal06);
WriteLine(4,"Hotaru","Oh,% Tomoko and Masahiro!+Will you help me get Kurumi down from that stage?",CHHotaruYukata02);
WriteLine(5,"Hotaru","I think she has been drinking a bit too much.",CHHotaruYukata02);
WriteLine(6,"Kurumi","Me,% drunk?% No, I`m just my usual self.+I don`t need to drink to be fun!+I don`t even like alcohol!",CHKurumiYukata02);
WriteLine(7,"Masahiro","Are we sure this is Kurumi we`re dealing with and not someone else?",CHMasahiroNormal08);
WriteLine(8,"Hotaru","Unfortunately,% she is.+At school she may act like she`s actually normal,% but when she`s somewhere else%.%.%.",CHHotaruYukata03);
WriteLine(9,"Tomoko","I know that story all too well%.%.%.",CHTomokoYukata03);
WriteLine(10,"Kurumi","Hey hey,% Ho-chan!+Wanna join me in a danmaku battle against those two?",CHKurumiYukata03);
WriteLine(11,"Hotaru","It`s Hotaru,% not Ho!+I hate that nickname!",CHHotaruYukata04);
WriteLine(12,"Masahiro","Why a danmaku battle?+Did I do something wrong?",CHMasahiroNormal05);
WriteLine(13,"Kurumi","Nothing is wrong,% but your fight with Ryo inspired me to make an even more intense display of danmaku!",CHKurumiYukata04);
WriteLine(14,"Masahiro","In that case,% sure.",CHMasahiroNormal06);
WriteLine(15,"Tomoko","Weren`t we going to hang our wish tags first?",CHTomokoYukata01);
WriteLine(16,"Masahiro","Oh,% that`s right!+But let`s finish this before we do that,% okay?",CHMasahiroNormal24);
WriteLine(17,"Tomoko","Never mind,% I`ll go by myself then.",CHTomokoYukata04);
WriteLine(18,"Masahiro",".%.%.%Oh?% Okay then.",CHMasahiroNormal19);
WriteLine(19,"Kurumi","I never thought I`d see the day where your dear childhood friend left you alone!",CHKurumiYukata05);
WriteLine(20,"Kurumi","Well then%.%.%.+Ho-chan,% you`ll still join me though!+And you get to go first too!",CHKurumiYukata03);
WriteLine(21,"Hotaru","Hold on a second!+Ahhh,% the music started%.%.%.",CHHotaruYukata05);

if(linenumber==1 && i==1){ nameappear=1; }
if(linenumber==2 && i==1){ nameappear=2; }

#include_function "script/Functions/TextWriter.txt";

} //>starttime

if((linenumber==lastline || linenumber==21) && wait==1){ SetCommonData("PlayMusic",2); }
if(skipped==2 && wait==1){ SetCommonData("PlayMusic",2); }


if(linenumber==lastline && wait==60){
	SetShotColor(255,255,255);

	Obj_Delete(OBJleft);
	Obj_Delete(OBJright);
	Obj_Delete(OBJtextbar);

	SetCommonData("InEvent",0);
//	SetCommonData("BackgroundStop",0);

//	VanishEnemy; SetCommonData("Conversation",2); // end conversation
	SetLife(0); // start battle
}


time++;
frame++;
}

}